package com.example.actionbartest2;

import android.app.ActionBar;
import android.app.ActionBar.OnNavigationListener;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.SpinnerAdapter;
import android.widget.Toast;

public class MainActivity extends Activity implements OnNavigationListener {

	boolean is_icon_item = true;
	int index;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// ActionBar ab = getActionBar();
		// ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		//
		// ab.addTab(ab.newTab().setText("Tab1").setTabListener(this));
		// ab.addTab(ab.newTab().setText("Tab2").setTabListener(this));
		// ab.addTab(ab.newTab().setText("Tab3").setTabListener(this));

		SpinnerAdapter sa = ArrayAdapter.createFromResource(this,
				R.array.action_list,
				android.R.layout.simple_spinner_dropdown_item);

		ActionBar ab = getActionBar();
		ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
		ab.setListNavigationCallbacks(sa, this);

		index = 0;
	}

	@Override
	public boolean onNavigationItemSelected(int arg0, long arg1) {
		// TODO Auto-generated method stub
		if (index != arg0) {
			String list[] = getResources().getStringArray(R.array.action_list);

			Toast.makeText(this, list[arg0], Toast.LENGTH_SHORT).show();
		}
		index = arg0;

		return false;
	}

	// @Override
	// public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
	// // TODO Auto-generated method stub
	// Log.d("Tag", "onTabReselected-" + arg0.getText());
	// }
	//
	// @Override
	// public void onTabSelected(Tab arg0, FragmentTransaction arg1) {
	// // TODO Auto-generated method stub
	// Log.d("Tag", "onTabSelected-" + arg0.getText());
	// }
	//
	// @Override
	// public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
	// // TODO Auto-generated method stub
	// Log.d("Tag", "onTabUnselected-" + arg0.getText());
	// }

	// @Override
	// public boolean onCreateOptionsMenu(Menu menu) {
	//
	// // Inflate the menu; this adds items to the action bar if it is present.
	// getMenuInflater().inflate(R.menu.main, menu);
	//
	// MenuItem sm = menu.findItem(R.id.menu_search);
	// SearchView sv = (SearchView) sm.getActionView();
	// sv.setOnQueryTextListener(this);
	// sv.setSubmitButtonEnabled(true);
	// sv.setQueryHint("input query hint");
	//
	// if(is_icon_item){
	// sm.setShowAsActionFlags(
	// MenuItem.SHOW_AS_ACTION_IF_ROOM|
	// MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
	// }else{
	// sm.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM);
	// sv.setIconifiedByDefault(false);
	// }
	//
	// return true;
	// }
	//
	// @Override
	// public boolean onQueryTextChange(String arg0) {
	// // TODO Auto-generated method stub
	// Log.d("Tag", "onQueryTextChange-" + arg0);
	// return false;
	// }
	//
	// @Override
	// public boolean onQueryTextSubmit(String arg0) {
	// // TODO Auto-generated method stub
	// Log.d("Tag", "onQueryTextSubmit-" + arg0);
	// return false;
	// }

}
